package priv.conceit.study.book.thread.chapter1.parts5;

import java.util.concurrent.TimeUnit;

/**
 * 1.5.3
 * 线程模拟银行抽号机 runnable接口实现类
 * <p>
 * 方便多线程的线程控制于业务代码进行解耦
 *
 * @author Conceit
 * 2019/6/4 增加方法
 * @since 1.0.0, 2019/6/4
 */
public class TicketWindowRunnable implements Runnable {

	//最多出售的票数
	private final static int MAX = 100;


	//默认的起始张数
	//该参数不为static
	private int index = 0;

	@Override
	public void run() {
		while (index < MAX) {
			index++;
			System.out.println("窗口: " + Thread.currentThread() + " <--->  " + "出售第：" + index + "张票");
			try {
				TimeUnit.MILLISECONDS.sleep(200L);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
	}

}
